import Vue from 'vue'
import VueRouter from 'vue-router'
import LoginView from '../views/LoginView.vue'  // 直接加载所有组件

Vue.use( VueRouter )

const routes = [
  {
    path: '/',
    name: 'index',
    component: LoginView
  },
  {
    path: '/login',
    name: 'login',
    component: LoginView
  },
  {
    path: "/home",
    name: "home",
    // 懒加载组件： 当访问/home时，才加载组件：
    component: () => import( "../views/HomeView.vue" ),
    children: [
      {
        path: "", // 配置一个默认子路由，
        component: () => import( "../components/AccessLayer.vue" )
      },
      {
        path: "about",
        name: "about",
        // 懒加载组件： 当访问/home时，才加载组件：
        component: () => import( "../views/AboutView.vue" ),
        children: [
          {
            path: 'aboutgs',
            component: () => import( "../views/AboutGs.vue" ),
          },
          {
            path: 'aboutwh',
            component: () => import( "../views/AboutWh.vue" ),
          },
          {
            path: '',
            component: () => import( "../views/AboutWh.vue" ),
          },

        ]
      },
      {
        path: "product",
        name: "product",
        // 懒加载组件： 当访问/home时，才加载组件：
        component: () => import( "../views/ProductView.vue" )
      },
      {
        path: "product/:pid",
        name: "product",
        // 懒加载组件： 当访问/home时，才加载组件：
        component: () => import( "../views/ProductView.vue" )
      },
      {
        path: "order",
        name: "order",
        // 懒加载组件： 当访问/home时，才加载组件：
        component: () => import( "../views/OrderView.vue" )
      },
    ]

  },

]

const router = new VueRouter( {
  mode: 'history',
  base: process.env.BASE_URL,
  routes
} )

export default router
